package com.example.tests;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import java.util.Random;

import org.testng.annotations.Test;

import com.example.fw.Folders;

public class TestFolderDeletion extends TestBase {

	@Test
	public void testFolderDeletion(){
		Folders oldFolders = app.getFolderHelper().getFolders();
		
		int index = getValidRandomIndex(oldFolders);
		
		app.getFolderHelper().deleteFolder(index);
		
		Folders newFilders = app.getFolderHelper().getFolders();
		assertThat(newFilders, equalTo(oldFolders.whithout(index)));		
	}

	
	
	private int getValidRandomIndex(Folders folders) {	
		try { 
			return new Random().nextInt(folders.size()-1);			
		} catch (IllegalArgumentException e) {
			return 0;
		}
	}
}
